from fastapi import FastAPI

from app.settings.config import MYSQL_USER, MYSQL_PASSWORD, MYSQL_HOST, MYSQL_DB, MYSQL_PORT
from tortoise.contrib.fastapi import register_tortoise


def database_init_db(app: FastAPI):
    return register_tortoise(
        app,
        db_url=f'mysql://{MYSQL_USER}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DB}',
        modules={"models": ["app.model.mysql"]},
        generate_schemas=True,
        add_exception_handlers=True,
    )
